package generation.duration;

import java.util.ArrayList;
import java.util.List;

import mapping.Mapper;
import util.Utils;

public class DurationCellRepository {

	private static List<QuantifiedCell> cells = new ArrayList<QuantifiedCell>();;

	private static void populateList() {
		String[] cell1 = {"s", "s", "s", "s"};
		String[] cell2 = {"s", "s", "i"};
		String[] cell3 = {"i", "s", "s"};
		String[] cell4 = {"s", "i", "s"};
		String[] cell5 = {"i", "i"};
		String[] cell6 = {"i*", "i*", "i*",};
		String[] cell7 = {"q"}; 
		String[] cell8 = {"q*", "q*", "q*"};
		String[] cell9 = {"h"};
		String[] cell10 = {"h*", "h*", "h*"};
		String[] cell11 = {"w"};
		
		cells.add(new QuantifiedCell(CellSpeed.VERYFAST, cell1, 4));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell2, 3));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell3, 3));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell4, 3));
		cells.add(new QuantifiedCell(CellSpeed.NOTSOFAST, cell5, 2));
		cells.add(new QuantifiedCell(CellSpeed.NOTSOFAST, cell6, 3));
		cells.add(new QuantifiedCell(CellSpeed.NORMAL, cell7, 1));
		cells.add(new QuantifiedCell(CellSpeed.NORMAL, cell8, 3));
		cells.add(new QuantifiedCell(CellSpeed.SLOW, cell9, 1));
		cells.add(new QuantifiedCell(CellSpeed.SLOW, cell10, 3));
		cells.add(new QuantifiedCell(CellSpeed.VERYSLOW, cell11, 1));
	}
	
	private static void populateRegularList(){
		String[] cell1 = {"s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s", "s"};
		String[] cell2 = {"s", "s", "i", "s", "s", "i", "s", "s", "i", "s", "s", "i"};
		String[] cell3 = {"i", "s", "s", "i", "s", "s", "i", "s", "s", "i", "s", "s"};
		String[] cell4 = {"s", "i", "s", "s", "i", "s", "s", "i", "s", "s", "i", "s"};
		String[] cell5 = {"i", "i", "i", "i", "i", "i", "i", "i"};
		String[] cell6 = {"i*", "i*", "i*", "i*", "i*", "i*", "i*", "i*", "i*", "i*", "i*", "i*"};
		String[] cell7 = {"q", "q", "q", "q"}; 
		String[] cell8 = {"q*", "q*", "q*", "q*", "q*", "q*"};
		String[] cell9 = {"h", "h"};
		String[] cell10 = {"h*", "h*", "h*"};
		String[] cell11 = {"w"};
		
		cells.add(new QuantifiedCell(CellSpeed.VERYFAST, cell1, 4));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell2, 3));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell3, 3));
		cells.add(new QuantifiedCell(CellSpeed.FAST, cell4, 3));
		cells.add(new QuantifiedCell(CellSpeed.NOTSOFAST, cell5, 2));
		cells.add(new QuantifiedCell(CellSpeed.NOTSOFAST, cell6, 3));
		cells.add(new QuantifiedCell(CellSpeed.NORMAL, cell7, 1));
		cells.add(new QuantifiedCell(CellSpeed.NORMAL, cell8, 3));
		cells.add(new QuantifiedCell(CellSpeed.SLOW, cell9, 1));
		cells.add(new QuantifiedCell(CellSpeed.SLOW, cell10, 3));
		cells.add(new QuantifiedCell(CellSpeed.VERYSLOW, cell11, 1));
	}
	
	public static String[] getCellByInput(float input){
		ArrayList<QuantifiedCell> cells = getCellsBySpeed(Mapper.mapInputToSpeed(input));
		return cells.get(Utils.random(cells.size())).getCell();
	}
	
	private static ArrayList<QuantifiedCell> getCellsBySpeed(CellSpeed speed){
		
		populateList();
		ArrayList<QuantifiedCell> result = new ArrayList<QuantifiedCell>();
		for (QuantifiedCell cell : cells) {
			if(cell.getSpeed().equals(speed)){
				result.add(cell);
			}
		}
		return result;
	}
	
	public static QuantifiedCell getRandomCellBySpeed(CellSpeed speed){
		ArrayList<QuantifiedCell> cells = getCellsBySpeed(speed);
		return cells.get(Utils.random(cells.size()));
	}
	
}
